<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>角色信息页</title>
<!-- 下载并引入jquery easyUI -->
<link rel="stylesheet" type="text/css"
	href="../../js/jquery-easyui-1.9.5/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="../../js/jquery-easyui-1.9.5/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="../../js/jquery-easyui-1.9.5/themes/color.css">
<script type="text/javascript"
	src="../../js/jquery-easyui-1.9.5/jquery.min.js"></script>
<script type="text/javascript"
	src="../../js/jquery-easyui-1.9.5/jquery.easyui.min.js"></script>


</head>
<body>
	<!-- 数据列表  start -->
	<!-- 在页面中使用easy ui组件进行界面编程 ,数据表格组件 -->
	<table id="role_dg" title="用户列表" class="easyui-datagrid"
		style="width: 100%; height: 100%"
		url="../json/rolelist.json"
		toolbar="#role_toolbar" pagination="true" rownumbers="true"
		fitColumns="true" singleSelect="true" fit: true>
		<thead>
			<tr>
				<th field="cb" checkbox="true" align="center"></th>
				<!--  field字段需要与返回数据的属性名一致 -->
				<th field="id" align="center">管理员编号</th>
				<th field="name" width="50">姓名</th>
				<th field="remark" width="50">备注</th>
			</tr>
		</thead>
	</table>
	<!-- 工具条组件 -->
	<div id="role_toolbar">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-add" plain="true" onclick="newRole()">新增</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-edit" plain="true" onclick="editRole()">修改</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-remove" plain="true" onclick="destroyRole()">删除</a>
	</div>
	<!-- 数据列表 end  -->


	<!-- 新增和修改表单  start -->
	<div id="role_dlg" class="easyui-dialog"
		style="width: 400px; height: 320px; padding: 10px 20px" closed="true"
		buttons="#role_dlg-buttons">
		<div class="ftitle">角色管理</div>
		<form id="role_fm" enctype="multipart/form-data" method="post">
			<div class="fitem">
				<label>名称:</label> <input  name="name"
					style="width: 260px;" prompt="rolename"
					data-options="iconCls:'icon-man'" class="easyui-textbox"
					required="true">
			</div>
			<div class="fitem">
				<label>备注:</label> <input name="remark"
					class="easyui-textbox " data-options="multiline:true" style="height:100px;width:260px" data-options="iconCls:'icon-lock'"
					prompt="remark" >
			</div>
		</form>
	</div>
	<div id="role_dlg-buttons">
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok"
			onclick="saveRole()">保存</a> <a href="#" class="easyui-linkbutton"
			iconCls="icon-cancel"
			onclick="javascript:$('#role_dlg').dialog('close')">取消</a>
	</div>
	<!-- 新增和修改表单 end -->
	<script type="text/javascript">
		function newRole() {
			$('#role_dlg').dialog('open').dialog('setTitle', '新增角色');
			$('#role_fm').form('clear');
			url = '../../sys/role/add';
		}

		function editRole() {
			$('#role_fm').form('clear');
			var row = $('#role_dg').datagrid('getSelected');
			if (row) {
				$('#role_dlg').dialog('open').dialog('setTitle', '修改角色');
				$('#role_fm').form('load', row);
				url = '../../sys/role/edit?id='
						+ row.id;
			} else {
				$.messager.show({
					title : 'Info',
					timeout : 2000,
					msg : '请选择一条记录！'
				});
			}
		}

		function saveRole() {
			$('#role_fm').form('submit', {
				url : url,
				onSubmit : function() {
					return $(this).form('validate');
				},
				success : function(result) {
					var result = eval('(' + result + ')');
					if (!result.success) {
						$.messager.show({
							title : 'Error',
							timeout : 2000,
							msg : result.errorMsg
						});
					} else {
						$.messager.show({
							title : 'Info',
							timeout : 2000,
							msg : result.errorMsg
						});
					}

					$('#role_dlg').dialog('close'); // close the dialog
					$('#role_dg').datagrid('reload'); // reload the user data
				}
			});
		}

		function destroyRole() {
			var row = $('#role_dg').datagrid('getSelected');
			if (row) {
				$.messager
						.confirm(
								'Confirm',
								'确认删除?',
								function(r) {
									if (r) {
										$
												.post(
														'../../sys/role/delete',
														{
															id : row.id
														},
														function(result) {
															if (result.success) {
																$('#role_dg')
																		.datagrid(
																				'reload'); // reload the user data
															} else {
																$.messager
																		.show({ // show error message
																			title : 'Error',
																			timeout : 2000,
																			msg : result.errorMsg
																		});
															}
														}, 'json');
									}
								});
			} else {
				$.messager.show({
					title : 'Info',
					timeout : 2000,
					msg : '请选择一条记录！'
				});
			}
		}

		function imageFormatter(value, row, index) {

			return "<img  width='60' src='../../"+value+"'>";

		}

		function passwordFormatter(value, row, index) {
			return "******";
		}

	</script>
</body>
</html>